package cn.jhc.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnectionFactory {

	private static DataSource ds = null;
	static {
		try {
			Context ctx = new InitialContext();
			ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/college");

		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	
	ConnectionFactory() {
	}

	public static Connection getConnection(){
		Connection instance = null;
		try {
			instance = ds.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return instance;
	}
}
